/**
 * @param {string} s
 * @return {string}
 */
var removeDuplicates = function(s) {
  let arr = s.split("");
  for(let i = 0; i < arr.length; i++) {
    if(i == 0) continue;
    if(arr[i] == arr[i - 1]) {
      arr.splice(i - 1, 2);
      if(i - 2 > 0)
        i -= 2;
      else
        i = 0;
    }
  }
  return arr.join("");
};
let s = "abbaca";
console.log(removeDuplicates(s));
